<!DOCTYPE html>
<html lang="zh-cmn-Hans" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="https://www.eryansky.com/thymeleaf/shiro">
  <head>
    <title>密码修改-[[${T(com.eryansky.utils.AppConstants).getAppFullName()}]]</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;chrome=1" />
    <meta name="renderer" content="webkit">
    <link rel="shortcut icon" href="/static/img/favicon.ico" th:href="@{/static/img/favicon.ico}"/>
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css" th:href="@{/static/js/adminlte/bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css" th:href="@{/static/js/adminlte/dist/css/font-awesome.min.css}">
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css" th:href="@{/static/js/adminlte/dist/css/ionicons.min.css}">
    <link rel="stylesheet" href="bower_components/iconfont/iconfont.css" th:href="@{/js/iconfont/iconfont.css}">
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css" th:href="@{/static/js/adminlte/dist/css/AdminLTE.min.css}">
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css" th:href="@{/static/js/adminlte/dist/css/skins/_all-skins.min.css}">
    <link href="/static/js/jquery-jbox/2.3/Skins/Bootstrap/jbox.css" th:href="@{/static/js/jquery-jbox/2.3/Skins/Bootstrap/jbox.css}" rel="stylesheet" />
    <link href="/static/js/jquery-validation-1.19.3/dist/extend/jquery-validate-extend.min.css" th:href="@{/static/js/jquery-validation-1.19.3/dist/extend/jquery-validate-extend.min.css}" rel="stylesheet" />
    <style type="text/css">
      html {overflow: hidden;}
    </style>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="../plugins/ie9/html5shiv.min.js" th:src="@{/static/js/adminlte/plugins/ie9/html5shiv.min.js}"></script>
    <script src="../plugins/ie9/respond.min.js" th:src="@{/static/js/adminlte/plugins/ie9/respond.min.js}"></script>
    <![endif]-->
    <script type="text/javascript">
      var ctx = window.document.location.pathname.substring(0, window.document.location.pathname.indexOf('\/', 1));
      var ctxAdmin = ctx+'/a';
      var ctxStatic = ctx+'/static';
      var appURL = "[[${T(com.eryansky.utils.AppUtils).getClientAppURL()}]]";
    </script>
  </head>
  <body class="hold-transition skin-blue sidebar-mini fixed">
    <div>
      <div class="box box-info">
        <div class="box-header with-border">
          <h3 class="box-title" th:if="${type == '1'}">设置密码</h3>
          <h3 class="box-title" th:unless="${type == '1'}">修改密码</h3>
        </div>
        <!-- /.box-header -->
        <!-- form start -->
        <form id="inputForm" class="form-horizontal">
          <input type="hidden" class="form-control" name="id" th:value="${model.id}">
          <input type="hidden" class="form-control" id="type" name="type" th:value="${type}">
          <div class="box-body">
            <div id="div_ps" class="form-group" style="display: none;">
              <label for="ps" class="col-sm-2 control-label">原始密码</label>
              <div class="col-sm-10">
                <input type="hidden" class="form-control" th:if="${type == '1'}" name="ps">
                <input type="password" class="form-control" th:unless="${type == '1'}" id="ps" name="ps" placeholder="原始密码">
              </div>
            </div>
            <div class="form-group">
              <label for="newPs" class="col-sm-2 control-label">新密码</label>

              <div class="col-sm-10">
                <input type="password" class="form-control" id="newPs" name="newPs" placeholder="新密码">
              </div>
            </div>
            <div class="form-group">
              <label for="newPs2" class="col-sm-2 control-label">确认密码</label>
              <div class="col-sm-10">
                <input type="password" class="form-control" id="newPs2" name="newPs2" placeholder="确认密码">
              </div>
            </div>
          </div>
          <!-- /.box-body -->
          <div class="box-footer">
            <button type="button" onclick="savePs();"  class="btn btn-info pull-right">保存</button>
          </div>
          <!-- /.box-footer -->
        </form>
      </div>
    </div>
    <!-- ./wrapper -->
    <!-- REQUIRED JS SCRIPTS -->
    <script src="/static/js/jquery/jquery-1.12.4.min.js" th:src="@{/static/js/jquery/jquery-1.12.4.min.js}" ></script>
    <script src="/static/js/jquery/jquery-migrate-1.4.1.min.js" th:src="@{/static/js/jquery/jquery-migrate-1.4.1.min.js}" ></script>
    <script src="/static/js/jquery/jquery-extend.min.js" th:src="@{/static/js/jquery/jquery-extend.min.js}" ></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js" th:src="@{/static/js/adminlte/bootstrap/js/bootstrap.min.js}"></script>
    <!-- FastClick -->
    <script src="../plugins/fastclick/fastclick.js" th:src="@{/static/js/adminlte/plugins/fastclick/fastclick.js}"></script>

    <script src="/static/js/jquery-validation-1.19.3/dist/jquery.validate.min.js" th:src="@{/static/js/jquery-validation-1.19.3/dist/jquery.validate.min.js}"></script>
    <script src="/static/js/jquery-validation-1.19.3/dist/extend/jquery-validate-extend-methods.min.js" th:src="@{/static/js/jquery-validation-1.19.3/dist/extend/jquery-validate-extend-methods.min.js}"></script>
    <script src="/static/js/common/common.min.js" th:src="@{/static/js/common/common.min.js}"></script>
    <script src="/static/js/jquery-jbox/2.3/jquery.jBox-2.3.min.js" th:src="@{/static/js/jquery-jbox/2.3/jquery.jBox-2.3.min.js}" type="text/javascript"></script>
    <script src="/static/js/jquery-jbox/2.3/i18n/jquery.jBox-zh-CN.min.js" th:src="@{/static/js/jquery-jbox/2.3/i18n/jquery.jBox-zh-CN.min.js}" type="text/javascript"></script>

    <script type="text/javascript">
      var $validator;
      var token = "[[${token}]]";
      var fromLogin = "[[${fromLogin}]]";
      var fromExtend = "[[${fromExtend}]]";
      var isCheckPasswordPolicy = "[[${isCheckPasswordPolicy}]]";
      $(function () {
        toggole();
        $validator = $("form").validate({
          rules: {
            newPs: {
              required: true,
              safepass: isCheckPasswordPolicy === "true"
            },
            newPs2: {
              required: true,
              equalTo: "#newPs"
            }
          },
          messages: {
            newPs2:{
              equalTo:"两次输入密码不一致"
            }
          }
        });

      });

      function toggole(){
        if($("#type").val() === "1"){//初始化密码
          $("#div_ps").hide();
        }else{//修改密码
          $("#div_ps").show();
        }
      }

      function savePs(){
        var valid = $("form").valid();
        if(!valid){
          // showTip("表单校验不通过，请完善相关数据！");
          return false;
        }

        var formData = $.serializeObject($("form"));
        formData = $.extend(formData,{'encrypt':false,'token':token});
        $.ajax({
          url: appURL + '/m/sys/user/savePs',
          type: 'POST',
          dataType: 'json',
          // headers:{'Authorization':'Bearer '+token},
          data:formData,
          success: function (data) {
            if (data.code === 1) {
              showTip(data['msg']);
              window.setTimeout(function(){
                if(fromLogin || fromExtend){
                  window.location.href = "[[${homeUrl}]]";
                }else{
                  window.location.reload();
                }
              },2*1000);
              // $("form")[0].reset();
              // $("#type").val(data['obj'] ?? '2');
              // toggole();
            } else {
              showTip(data['msg']);
            }
          }
        });
      }
    </script>

  </body>
</html>